 <form class="layui-form layui-user-from" method="post">
        <div class="layui-row">
            <div class="layui-col-md3 layui-col-sm12">
                <div class="layui-form-item">
                    <label class="layui-form-label">客户名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="clientName"   placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3 layui-col-sm12">
                <div class="layui-form-item">
                    <label class="layui-form-label">客户编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="clientId" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-md3">
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-bg-lightblue" lay-submit lay-filter="projectClientSearch">搜索</button>
                        <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">清空</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <table class="layui-hide" id="projectClientTableId" lay-filter="projectClientTableId" lay-skin="line"></table>
<script>
    layui.use(['form', 'table', 'miniPage', 'element', 'laydate', 'laytpl'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            laydate = layui.laydate,
            laytpl = layui.laytpl

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        /**
         * 数据快速查看
         **/
        var tableIns = table.render({
            elem: '#projectClientTableId',
            url: 'api/project/project_client.json',
            toolbar: '#projectClientToolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: [],
            skin: 'line',
            cols: [
                [
                    {field: 'id', align:'center',  title: '客户编号',sort: true},
                    {field: 'clientName', align:'center',title: '客户中文名称'},
                    {field: 'clientType', align:'center',  title: '客户类型',sort: true},
                    {title: '操作',  fixed: "right", align: "center", templet: function(d){
                            var _str = '';
                            _str +='<button class="layui-btn layui-btn-xs layui-btn-primary add_program" lay-event="details" data-contact="'+ d.contact+'" data-id = "'+d.id+'" >选择</button>'
                            return _str;
                        }
                    }
                ]
            ],
            page: true, //开启分页
            request: {
                pageName: 'pageIndex', // page
                limitName: 'pageSize' // limit
            }
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
        });

        /*$('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });*/

        form.on('submit(projectClientSearch)', function(data){
            data.field.pageIndex = 1;
            tableIns.reload({
                where: data.field
            });
            return false;
        });

        table.on('tool(projectClientTableId)', function(obj){
            var data = obj.data;
            var _id  = data.id;
            //编辑
            if(obj.event === 'details') {
                var clientNumber = $(this).data("id");//clientNumber 为客户ID
                var contact = $(this).data("contact");
                if (contact == 0) {
                    layer.msg("请先添加客户的联系人信息", {
                        time: 1000, //1s后自动关闭
                    });
                    return false;
                }

                layer.close(parentIndex);

                var content = miniPage.getHrefContent('page/project/edit.html');<!--此处替换添加控制器地址-->
                    layer.open({
                        title: '添加项目',
                        area:['60%','60%'],
                        type: 1,
                        shade: 0.2,
                        maxmin:true,
                        shadeClose: true,
                        content: content,
                        end: function () {
                            //执行重载
                            table.reload('projectClientTableId', {
                                /*page: {
                                    curr: 1 //重新从第 1 页开始
                                }*/
                            }, 'data');
                        }
                    });
            }
        });
    });
</script>
